angular.module("app").directive("appCounttime", ["$interval", "product", function ($interval, product) {

    return {
        restrict: "AE",
        replace: true,
        transclude: true,
        templateUrl: "views/template/Countdown.html",
        scope: {
            time: "@"
        },
        link: function (scope, ele, attr) {
            
            var mydate=scope.time
            function GetTime() {
                var time = new Date(mydate.replace(/-/g,'/')).getTime()
                var nowTime = new Date().getTime()
                var CountDown = time - nowTime
                var h = parseInt(CountDown / 1000 / 60 / 60)
                var m = parseInt(CountDown / 1000 / 60 % 60)
                var s = parseInt(CountDown / 1000 % 60)
               return scope.time = addZero(h) + ":" + addZero(m) + ":" + addZero(s)
            }
            var timer = $interval(function () {
                GetTime()
            }, 1000)
            product.timers.push(timer)
            

            function addZero(num) {
				if(num < 10) {
					return "0" + num.toString()
				} else {
					return num
				}
			}




        }

    }

}])